﻿/* 变量 */
var picture = "other/picture.html";
var video = "other/video.html";




//赏美图
var contactsCallback_picture = myApp.onPageInit('picture', function (page) {

    var conditionParams = JSON.stringify({
        type: "7",
        Identifier: "wechat/picture",
    });

    // 美图欣赏
    $$.ajax({
        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.CMS,
        data: { "content": conditionParams },
        crossDomain: true,
        method: "POST",
        dataType: "jsonp",
        success: function (data, status) {
            data = JSON.parse(data);
            if (data && data.status && data.status == "0" && data.results && data.results.length > 0) {
                for (var i = 0; i < data.results.length; i++) {
                    // 格式化数据
                    for (var j = 0; j < data.results[i].value.length; j++) {
                        if (data.results[i].value[j].F_SmallImage == undefined || data.results[i].value[j].F_SmallImage == null || data.results[i].value[j].F_SmallImage == "") {
                            data.results[i].value[j].F_SmallImage = NoPicture();
                        };
                        if (data.results[i].value[j].Head != undefined && data.results[i].value[j].Head != null && data.results[i].value[j].Head != "" && data.results[i].value[j].Head.length > 6) {
                            data.results[i].value[j].Head = data.results[i].value[j].Head.substring(0,6);
                        };
                    }
                    if (data.results[i].name == "picture") {
                        var searchTemplate = $$('#template-picture-tab1').html();
                        if (searchTemplate) {
                            var compiledTemplate = Template7.compile(searchTemplate);
                            var html = compiledTemplate(data.results[i]);
                            $$("#picture_page .content-block").html(html);
                        }
                    }
                }
            }
        },
        error: function (xhr, status) { }
    });

    //图片浏览器
    $$('#picture_page .page-content').on('click', "a", function (e) {
        var photos = [];
        var imageList = $$(this).find("img").attr("data-img").split(",");
        if (imageList == undefined || imageList == "" || imageList.length == undefined || imageList.length == 0) return;

        $$.each(imageList, function (i, obj) {
            if(obj != undefined && obj != null && obj != ""){
                photos.push({ url: obj, caption: "" });
            }
        });

        var myPhotoBrowser = myApp.photoBrowser({
            zoom: true,
            exposition: true,
            navbar: true,
            backLinkText: "返回",
            ofText: " / ",
            theme: 'dark',
            photos: photos
        });
        myPhotoBrowser.open(); // 打开图片浏览器
    });

});

//赏视频
var contactsCallback_video = myApp.onPageInit('video', function (page) {


});

/* 初始化  */
function initData() {
    var href = window.location.href;
    if (href.indexOf(picture) > -1) {
        contactsCallback_picture.trigger();
    }
    else if (href.indexOf(video) > -1) {
        contactsCallback_video.trigger();
    }
}

initData();